//
//  DataController.m
//  SHWT
//
//  Created by Rui on 14/10/23.
//  Copyright (c) 2014年 xingheng. All rights reserved.
//

#import "DataController.h"

@implementation DataController

/**
 *  用户登陆
 *
 *  @param telNum    手机号/用户名
 *  @param password  登录密码
 *  @param loginType 登录类型
 *  @param imei      设备号
 *  @param success   成功回调
 */
+ (void)userLogin:(NSString *)telNum
         password:(NSString *)password
        loginType:(NSString *)loginType
             imei:(NSString *)imei
        withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     telNum,@"telNum",
                                   password,@"password",
                                  loginType,@"loginType",
                                       imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/user/userLogin"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];
}

/**
 *  重置密码
 *
 *  @param loginName        登录账号
 *  @param telNum           手机号/用户名
 *  @param verificationCode 验证码
 *  @param newPassword      新密码
 *  @param userType         用户类型
 *  @param success          成功回调
 */
+ (void)resetPassword:(NSString *)loginName
               telNum:(NSString *)telNum
     verificationCode:(NSString *)verificationCode
          newPassword:(NSString *)newPassword
             userType:(NSString *)userType
            withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     loginName,@"loginName",
                                        telNum,@"telNum",
                              verificationCode,@"verificationCode",
                                   newPassword,@"newPassword",
                                      userType,@"userType", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/user/resetPassword"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"失败");
         NSLog(@"Error: %@", error);
     }];
}

/**
 *  获取司机当前货单信息
 *
 *  @param driverId 司机id
 *  @param userId   用户id
 *  @param imei     设备号
 *  @param success  成功回调
 */
+ (void)getDriverCurOrder:(NSNumber *)driverId
                   userId:(NSNumber *)userId
                     imei:(NSString *)imei
                withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     driverId,@"driverId",
                                       userId,@"userId",
                                         imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getDriverCurOrder"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];

}

/**
 *  获取司机历史货单列表信息
 *
 *  @param driverId 司机id
 *  @param userId   用户id
 *  @param lastId   最小id
 *  @param imei     设备号
 *  @param success  成功回调
 */
+ (void)getDriverHisOrder:(NSNumber *)driverId
                   userId:(NSNumber *)userId
                   lastId:(NSNumber *)lastId
                     imei:(NSString *)imei
                withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     driverId,@"driverId",
                                     userId,@"userId",
                                     lastId,@"lastId",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getDriverHisOrder"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSLog(@"成功");
         success(responseObject);
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];

}

/**
 *  获取货单详细信息
 *
 *  @param orgId    orgId
 *  @param userId   userId
 *  @param userType userType
 *  @param imei     imei
 *  @param success  成功回调
 */
+ (void)getOrderDetail:(NSNumber *)orderId
                userId:(NSNumber *)userId
              userType:(NSString *)userType
                  imei:(NSString *)imei
             withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     orderId,@"orderId",
                                     userId,@"userId",
                                     userType,@"userType",
                                     imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/order/getOrderDetail"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

/**
 *  获取司机告警次数信息
 *
 *  @param driverId 司机id
 *  @param userId   用户id
 *  @param imei     设备号
 *  @param success  成功回调
 */
+ (void)getDriverAlarmTimes:(NSNumber *)driverId
                     userId:(NSNumber *)userId
                       imei:(NSString *)imei
                  withBlock:(void(^)(NSDictionary *result))success{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSMutableDictionary * dicJson = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                     driverId,@"driverId",
                                       userId,@"userId",
                                         imei,@"imei", nil];
    
    [manager POST:@"http://221.207.138.101:58080/whb-ws/alarm/getDriverAlarmTimes"
       parameters:dicJson
          success:^(AFHTTPRequestOperation *operation, id responseObject){
              success(responseObject);
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error){
              NSLog(@"Error: %@", error);
          }];
}

@end